package cn.tedu.smartmarketing.user.service.impl;

import cn.tedu.smartmarketing.user.mapper.BehaviorMapper;
import cn.tedu.smartmarketing.user.pojo.dto.BehaviorParam;
import cn.tedu.smartmarketing.user.pojo.entity.Behavior;
import cn.tedu.smartmarketing.user.pojo.vo.BehaviorVo;
import cn.tedu.smartmarketing.user.service.BehaviorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class BehaviorServiceImpl implements BehaviorService {
    @Autowired
    BehaviorMapper behaviorMapper;
    @Override
    public void record(BehaviorParam behaviorParam) {
    log.debug("behaviorParam:{}",behaviorParam);
        Behavior behavior = new Behavior();
        BeanUtils.copyProperties(behaviorParam,behavior);
        behavior.setStarttime(new Date());
        behavior.setEndtime(new Date());
        behaviorMapper.insert(behavior);
    }

    @Override
    public List<BehaviorVo> list(Integer userId) {
        if (userId!=null){
            List<BehaviorVo> behaviorVos = behaviorMapper.list(userId);
            return behaviorVos;
        }
        return Collections.emptyList();
    }
}
